CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
PROJECT(bigflow)

SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ADD_DEFINITIONS(-DTOFT_CXX11_ENABLED -DBASE_CXX_ENABLED)
ADD_COMPILE_OPTIONS(-fPIC)
ADD_COMPILE_OPTIONS(-fpermissive)

# todo: move init.sh to a build-support dir
EXECUTE_PROCESS(COMMAND sh ${PROJECT_SOURCE_DIR}/init.sh)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR})

#TODO check pthread
SET(CMAKE_HAVE_PTHREAD_H 1)

SET(EXTERNAL_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/thirdparty)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

OPTION(WITH_TESTING "Compile Bigflow with unit testing" ON)
SET(THIRD_PARTY_PATH "${CMAKE_BINARY_DIR}/thirdparty" CACHE STRING
      "A path setting third party libraries download & build directories.")

INCLUDE_DIRECTORIES("$ENV{JAVA_HOME}/include")
IF(APPLE)
    INCLUDE_DIRECTORIES($ENV{JAVA_HOME}/include/darwin)
ELSE()
    INCLUDE_DIRECTORIES("$ENV{JAVA_HOME}/include/linux")
ENDIF()

INCLUDE_DIRECTORIES(${EXTERNAL_INSTALL_LOCATION})
INCLUDE_DIRECTORIES(${EXTERNAL_INSTALL_LOCATION}/hdfs/src)
INCLUDE_DIRECTORIES(${EXTERNAL_INSTALL_LOCATION}/include)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/flume/proto)
LINK_DIRECTORIES(${EXTERNAL_INSTALL_LOCATION}/lib)

INCLUDE(generic)
INCLUDE(thrift)
INCLUDE(python)
INCLUDE(boost)
INCLUDE(cityhash)
INCLUDE(libev)
INCLUDE(protobuf)
INCLUDE(snappy)
INCLUDE(leveldb)
INCLUDE(re2)
INCLUDE(tinyxml)
INCLUDE(krb)
INCLUDE(libxml2)
INCLUDE(libgsasl)
INCLUDE(uuid)
INCLUDE(hdfs)
INCLUDE(ctemplate)
INCLUDE(gflags)
INCLUDE(glog)
INCLUDE(gtest)
INCLUDE(stringencoders)
# brpc cannot be compiled on mac yet
IF(NOT APPLE)
    INCLUDE(brpc)
ENDIF()

#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
ADD_SUBDIRECTORY("toft")

#set(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/.libs)
ADD_SUBDIRECTORY("flume")
ADD_SUBDIRECTORY("bigflow_python")
